<?php
class SearchAccountTokenCategoryAction extends CAction{
	public function run($node){
		$node=intval($node);
		$model=AccountTokenCategory::model();
		$criteria=new CDbCriteria();
		if($node){
			$criteria->compare($model->getTableAlias().'.parentId', $node);
			$criteria->with=array('parent');
		}else{
			$criteria->addInCondition('parentId', array(null));
		}
		$categories=$model->findAll($criteria);
		$result=array();
		foreach($categories as $category){
			$result[]=array(
				'id'=>$category->id,
				'name'=>$category->name,
				'displayLongName'=>$category->getDisplayLongName(),
			);
		}
		echo CJSON::encode($result);
	}
}